home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15745 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Stylistic Concerns with Header Files
  5. Date: 21 Apr 1996 15:22:10 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4ldjr2$88p@sparcserver.lrz-muenchen.de>
  9. References: <4lb9bl$amo@wormer.fn.net>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. withheld@keepitpublic.com (Rusty Meathook) writes:
  13.  
  14. >I occasionally create the undesirable situation of having to include
  15. >my header files in a certain order, or having to include one header
  16. >file to include another, and I was wondering how I can circumvent
  17. >that.
  18.  
  19. [Two heades where header two needs header one edited]
  20.  
  21. >Of course, these are intentionally simple examples, and there are
  22. >obvious ways to solve the problem by merging the two header files.
  23. >Imagine, however, that it is undesirable to merge the header files --
  24. >each of them deals with a different library of functions, and need to
  25. >be kept seperate to maintain modularity.
  26.  
  27. >The obvious problem, now, is that a source file that needs to use
  28. >"foo.h" will have to include "bar.h" prior to including "foo.h", which
  29. >is a nasty situation stylistically.  Including another header file
  30. >within a header file is even worse.
  31.  
  32. Why is this "worse"? You either have to include header files in a
  33. certain order, or every header file has to include all the header
  34. files needed by that header file. The 
  35.  
  36.   #ifndef INCL_FOO_H
  37.   #define INCL_FOO_H
  38.  
  39.   #endif
  40.  
  41. construct prevents multiple inclusions of a header files contents.
  42.  
  43. From a maintainers point of view, I prefer this scheme over having
  44. to know which other header files have to be included before you can 
  45. include a given header file.
  46.  
  47. You _do_ have a problem if there are circular dependencies, but they
  48. usually can be solved using forward references.
  49.  
  50. Kurt
  51. --
  52. | Kurt Watzka                             Phone : +49-89-2180-6254
  53. | watzka@stat.uni-muenchen.de
  54.